home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: processStats.C,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:56:03 $
- */
- /*
- * stats.c
- *
- * Member functions for the stats classes.
- */
-
- #include <stdio.h>
- #include "processStats.h"
-
- const int THOU = 1000;
-
- extern int IO_DiskReads;
- extern int IO_DiskWrites;
-
- /*
- * The Start() function starts the collecting of stats
- * for a Unix process.
- */
- void
- ProcessStats::Start()
- {
- /*
- * Save the current stats in buffer area 1.
- */
- getrusage(RUSAGE_SELF, &rusage1);
- gettimeofday(&time1, NULL);
-
- smPagesRead1 = IO_DiskReads;
- smPagesWrite1 = IO_DiskWrites;
-
- return;
- }
-
-
- /*
- * The Stop() function stops the collecting of stats
- * for a Unix process.
- */
- void
- ProcessStats::Stop()
- {
- /*
- * Save the final stats in buffer area 2.
- */
- gettimeofday(&time2, NULL);
- getrusage(RUSAGE_SELF, &rusage2);
-
- smPagesRead2 = IO_DiskReads;
- smPagesWrite2 = IO_DiskWrites;
-
- return;
- }
-
-
- /*
- * The RealTime() function returns the
- * elapsed real time in micro-seconds (as measured by Unix)
- * between the Start() call and the last Stop() call.
- */
- float
- ProcessStats::RealTime()
- {
- return 1000000.0 * (time2.tv_sec - time1.tv_sec) +
- (time2.tv_usec - time1.tv_usec);
- }
-
-
- /*
- * The UserTime() function returns the Unix process
- * elapsed user time in micro-seconds between the Start()
- * call and the last Stop() call.
- */
- float
- ProcessStats::UserTime()
- {
- return 1000000. * (rusage2.ru_utime.tv_sec - rusage1.ru_utime.tv_sec) +
- (rusage2.ru_utime.tv_usec - rusage1.ru_utime.tv_usec);
- }
-
-
- /*
- * The SystemTime() function returns the Unix process
- * elapsed system time in micro-seconds between the Start()
- * call and the last Stop() call.
- */
- float
- ProcessStats::SystemTime()
- {
- return 1000000.0 * (rusage2.ru_stime.tv_sec - rusage1.ru_stime.tv_sec) +
- (rusage2.ru_stime.tv_usec - rusage1.ru_stime.tv_usec);
- }
-
-
- /*
- * The PageRelcaims() function returns the number of
- * Unix process page reclaims between the Start() call and
- * the last Stop() call.
- */
- int
- ProcessStats::PageReclaims()
- {
- return rusage2.ru_minflt - rusage1.ru_minflt;
- }
-
-
- /*
- * The PageFaults() function returns the number of
- * Unix process page faults between the Start() call and
- * the last Stop() call.
- */
- int
- ProcessStats::PageFaults()
- {
- return rusage2.ru_majflt - rusage1.ru_majflt;
- }
-
-
- /*
- * The Swaps() function returns the number of
- * Unix process swaps between the Start() call and
- * the last Stop() call.
- */
- int
- ProcessStats::Swaps()
- {
- return rusage2.ru_nswap - rusage1.ru_nswap;
- }
-
-
- /*
- * The PageIns() function returns the number of
- * Unix page-ins between the Start() call and
- * the last Stop() call.
- */
- int
- ProcessStats::PageIns()
- {
- return rusage2.ru_inblock - rusage1.ru_inblock;
- }
-
-
- /*
- * The PageOuts() function returns the number of
- * Unix page-outs between the Start() call and
- * the last Stop() call.
- */
- int
- ProcessStats::PageOuts()
- {
- return rusage2.ru_oublock - rusage1.ru_oublock;
- }
-
- /*
- * The smPagesRead() function returns the number of
- * sm pages read between the Start() call and
- * the last Stop() call.
- */
- int
- ProcessStats::smPagesRead()
- {
- return smPagesRead2 - smPagesRead1;
- }
-
- /*
- * The smPagesWrite() function returns the number of
- * sm pages written between the Start() call and
- * the last Stop() call.
- */
- int
- ProcessStats::smPagesWrite()
- {
- return smPagesWrite2 - smPagesWrite1;
- }
-
- void
- ProcessStats::PrintStatsHeader(FILE *f)
- {
- fprintf(f, "%-10s %6s %6s %6s %5s %5s %5s %4s %4s %4s %4s\n",
- " ", "Real", "User", "System", "smIn", "smOut", "Reclm",
- "Pflt", "Swap", "PgIn", "PgOt");
- }
-
- void
- ProcessStats::PrintStats(FILE *f, char *prefix)
- {
- fprintf(f, "%-10s %6d %6d %6d %5d %5d %5d %4d %4d %4d %4d\n",
- prefix, (int)(RealTime()/THOU), (int)(UserTime()/THOU),
- (int)(SystemTime()/THOU), smPagesRead(), smPagesWrite(),
- PageReclaims(), PageFaults(), Swaps(), PageIns(), PageOuts());
- }
-
-
-